/*
* Copyright 2008 Google Inc. 
* Licensed under the Apache License, Version 2.0:
*  http://www.apache.org/licenses/LICENSE-2.0
*/
package {

import com.google.maps.LatLng;
import com.google.maps.Map;

import flash.events.MouseEvent;
import flash.net.*;

import mx.containers.Box;
import mx.controls.Image;
import mx.controls.Label;
import mx.controls.LinkButton;
import mx.core.UIComponent;

public class InfoWindowBody extends UIComponent {
  public var zoomedIn:Boolean = false;
  
  public function InfoWindowBody(map:Map, latlng:LatLng, location:String, imgUrl:String, clickUrl:String, message:String) {
    
    var box:Box = new Box();
    box.setStyle("horizontalAlign", "center");
    box.width = 300;
    box.height = 270;
   
    var bodyTextField:Label = new Label();
    bodyTextField.setStyle("textAlign", "center");
    bodyTextField.percentWidth = 100;
    bodyTextField.htmlText = "<center><b>" + location + "</b></center>";
    bodyTextField.selectable = false;
    box.addChild(bodyTextField);
    
    var img:Image = new Image();
    img.source = imgUrl;
    img.width = 200;
    img.height = 180;
    box.addChild(img);
    
    var clickMore:LinkButton = new LinkButton();
    clickMore.percentWidth = 100;
    clickMore.label = message;
    clickMore.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
    	var request:URLRequest = new URLRequest(clickUrl);
        navigateToURL(request, "_blank");
        // todo: catch errors?
    });
    box.addChild(clickMore);
    
    var zoomIn:LinkButton = new LinkButton();
    zoomIn.percentWidth = 100;
    if (map.getZoom() < 16) {
        zoomIn.label = "Zoom In";
        zoomedIn = false;
    } else {
    	zoomIn.label = "Zoom Out";
    	zoomedIn = true;
    }
    zoomIn.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void {
    	if (!zoomedIn) {
    	   zoomedIn = true;
    	   map.setCenter(latlng, 16);
    	   zoomIn.label = "Zoom Out";
    	} else {
    		zoomedIn =false;
    		map.setCenter(latlng, 2);
    		zoomIn.label = "Zoom In";
    	}
    });
    box.addChild(zoomIn);
    addChild(box);   
    
    cacheAsBitmap = true;
  }
}

}
